﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using CrmDocman.DataCore;

/// <summary>
/// Summary description for CauHinhHelper
/// </summary>
public class CauHinhHelper : TWSData
{
    public CauHinhHelper()
    {
        m_dao = DataBridge.GetInstance();
    }

    public CauHinhDataSet LoadCauHinh()
    {

        CauHinhDataSet lspDs = new CauHinhDataSet();
        string sql = m_dao.BuildSelectQuery(lspDs.CauHinh);
        sql += " order by ThuTu ";

        m_dao.FillDataTable(lspDs.CauHinh, sql);
        m_dao.Connection.CloseConnection();
        return lspDs;
    }

    public CauHinhDataSet LoadCauHinh(string tenCauHinh)
    {

        CauHinhDataSet lspDs = new CauHinhDataSet();
        string sql = m_dao.BuildSelectQuery(lspDs.CauHinh);
        sql += " where TenCauHinh = '" + tenCauHinh+"'";

        m_dao.FillDataTable(lspDs.CauHinh, sql);
        m_dao.Connection.CloseConnection();
        return lspDs;
    }

    public bool SaveCauHinh(CauHinhDataSet lspDs)
    {
        m_dao.UpdateDataTable(lspDs.CauHinh);
        m_dao.Connection.CloseConnection();
        return true;

    }

    public static string GetCauHinh(string tenCauHinh)
    {
        if (!new CauHinhHelper().LoadCauHinh(tenCauHinh).CauHinh[0].IsThongSo1Null())
        {
            return new CauHinhHelper().LoadCauHinh(tenCauHinh).CauHinh[0].ThongSo1;
        }
        return "";
    }
}